package com.iocup.keybastion.authorize.decision;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * 默认的权限决断器查询
 * @author xyjxust
 * @create 2022/3/2 10:56
 **/
public class DefaultAuthDecisionFinder implements AuthDecisionFinder {


    private Map<String, AuthDecision> decisionMap = new HashMap<>();


    @Override
    public Optional<AuthDecision> find(String name) {
        if (!decisionMap.containsKey(name)) {
            return Optional.empty();
        }
        return Optional.of(decisionMap.get(name));
    }

    @Override
    public AuthDecisionFinder addDecision(AuthDecision decision) {
        decisionMap.put(decision.getType(), decision);
        return this;
    }
}
